package com.gyf.usercenter.ui.presenter

import com.gyf.base.ext.execute
import com.gyf.base.presenter.BasePresenter
import com.gyf.base.rx.BaseSubscriber
import com.gyf.usercenter.service.UserService
import com.gyf.usercenter.service.lmpl.UserServiceImpl
import com.gyf.usercenter.ui.presenter.view.RegisterView
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class RegisterPresenter @Inject constructor() : BasePresenter<RegisterView>() {
    @Inject
    lateinit var userService: UserService

    fun register(mobile: String, pwd: String, verifyCode: String) {
        if (!checkNetWork()) {
            return;
        }
        mView.showLoading();
        userService.register(mobile, pwd, verifyCode)
                .execute(object : BaseSubscriber<Boolean>(mView) {
                    override fun onNext(t: Boolean?) {
                        super.onNext(t);
                        if (t != null && t)
                            mView.onRegisterResult("注册成功");
                    }
                }, lifecycleProvider);
    }
}